=<template>
	<view>
		<!-- 头部 -->
		<myHead :title="title"></myHead>

		<!-- 搜索框 -->
		<view class="index-search">
			<text class="iconfont icon-sousu"></text>
			<input type="text" placeholder="搜索歌曲" />
		</view>

		<!-- 热搜内容 -->
		<view>
			<view class="hotTitle">
				热门搜索：
			</view>
			<view v-for="(hot, index) in hotSearchList" :key="index">{{ hot }}</view>
		</view>
	</view>
</template>

<script>
	import myHead from '../../components/myHead/myHead.vue'
	// 导入 searchHot 函数
	import {
		searchHot
	} from '../../commom/api.js'

	export default {
		components: {
			myHead
		},
		data() {
			return {
				title: "搜索页面",
				hotSearchList: [] // 存储热搜内容
			}
		},
		mounted() {
			// 页面加载时调用获取热搜内容的函数
			this.getHotSearch()
		},
		methods: {
			// 获取热搜内容
			async getHotSearch() {
				try {
					const res = await searchHot()
					// 如果请求成功，将热搜数据存储在 hotSearchList 变量中
					if (res.data.code === 200) {
						this.hotSearchList = res.data.data.map(item => item.searchWord);

					}
				} catch (error) {
					console.error('获取热搜内容失败:', error)
				}
			}
		}
	}
</script>

<style>
	.index-search {
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		background: #f7f7f7;
		border-radius: 50rpx;
	}

	.index-search .iconsearch {
		width: 40rpx;
		height: 40rpx;
	}

	.index-search text {
		font-size: 40rpx;
		margin-right: 26rpx;
		margin-left: 28rpx;
	}

	.index-search input {
		font-size: 28rpx;
		flex: 1;
	}
	.hotTitle{
		font-size: 24px;
	}
</style>